<template>
  <a-spin class="wrapper" :loading="loading" style="width: 100%; position: relative;">
    <a-tabs default-active-key="1" lazy-load>
      <a-tab-pane key="1">
        <template #title>
          Arco Design Icons
          <a-badge :count="ArcoDesignIcons.length" :max-count="999" />
        </template>
        <div class="icon-title"></div>
        <ul class="icon-list back-top1">
          <li class="icon-item" v-for="(item, index) in ArcoDesignIcons" :key="index" @click="iconSelected(item)">
            <div class="icon-item-name">{{ item }}</div>
            <div class="icon-item-component">
              <icon-xigua-color />
            </div>
          </li>
        </ul>
        <a-back-top target-container=".back-top1" :style="{ position: 'absolute' }"/>
      </a-tab-pane>
      <a-tab-pane key="2">
        <template #title>
          Iconfont Icons
          <a-badge :count="IconFontIcons.length" :max-count="999" />
        </template>
        <div class="icon-title"></div>
        <ul class="icon-list back-top2">
          <li class="icon-item" v-for="(item, index) in IconFontIcons" :key="index" @click="iconSelected(item)">
            <div class="icon-item-name">{{ item }}</div>
            <div class="icon-item-component">
              <icon-font :type="item"/>
            </div>
          </li>
        </ul>
        <a-back-top target-container=".back-top2" :style="{ position: 'absolute' }"/>
      </a-tab-pane>
    </a-tabs>
  </a-spin>
</template>

<script lang="ts" setup>
  // import { ref } from 'vue';
  import { Icon } from '@arco-design/web-vue';

  import useLoading from '@/hooks/loading';
  import ArcoDesignIcons from './arco-design';
  import IconFontIcons from './iconfont';

  const { loading, setLoading } = useLoading(true);

  const emit = defineEmits(['okCallback']);

  const IconFont = Icon.addFromIconFontCn({ src: 'https://at.alicdn.com/t/c/font_3611618_x2s43yrhl0j.js' });
  const fetchData = async () => {
    setLoading(false);
  };
  const iconSelected = (icon: string) => {
    emit('okCallback', icon);
  };

  fetchData();
</script>

<style scoped lang="less">
  .icon-title {
    border-bottom: 1px solid var(--color-border);
  }

  .icon-list {
    display: flex;
    flex-wrap: wrap;
    margin: 0;
    padding: 0;
    list-style: none;
    border-left: 1px solid var(--color-border);

    height: 500px;
    overflow: auto;
  }

  .icon-item {
    position: relative;
    box-sizing: border-box;
    width: 16.66%;
    height: 140px;
    border-right: 1px solid var(--color-border);
    border-bottom: 1px solid var(--color-border);
  }

  .icon-item-name {
    position: absolute;
    top: 10px;
    left: 10px;
    color: var(--color-text-1);
  }

  .icon-item-component {
    margin-top: 10px;
    font-size: 32px;
    line-height: 140px;
    text-align: center;
    cursor: pointer;
    transition: all .2s ease;
  }

  .icon-item-component:hover {
    font-size: 48px;
  }
</style>
